//
//  LGInPlayToolBar.swift
//  LGMusic
//
//  Created by 梁尚嘉 on 2017/4/7.
//  Copyright © 2017年 LimeGah. All rights reserved.
//

import UIKit

class LGInPlayToolBar: UIView {

    var items:[String]?
    var buttons = [UIButton]()

    class func toolBar(_ items:[String]) -> LGInPlayToolBar {
        let toolBar = LGInPlayToolBar.init(frame: CGRect.zero)
        toolBar.items = items
        toolBar.configure()
        return toolBar
    }


    func configure() -> Void {

        let view = UIView.init()
        self.addSubview(view)
        view.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.centerY.equalTo(self.snp.centerY)
            make.height.equalTo(self.snp.height)
        }

        var index = 0
        var button:UIButton?
        for item:String in self.items! {
            button = UIButton.init(frame:CGRect.zero)
            button?.setImage(UIImage.init(named: item), for: UIControlState.normal)
            button?.setImage(UIImage.init(named: item+"_press"), for: UIControlState.highlighted)
            view.addSubview(button!)
            self.buttons.append(button!)
            button?.snp.makeConstraints({ (make) in
                if index == 0 {
                    make.left.equalTo(SM_SIZE(0))
                }else {
                    if index == (self.items?.count)! - 1 {
                        make.right.equalTo(SM_SIZE(0))
                    }
                    let previousButton = self.buttons[index-1]
                    make.left.equalTo(previousButton.snp.right).offset(SM_SIZE(30))
                }
//                make.width.height.equalTo(SM_SIZE(60))
                make.centerY.equalTo(self.snp.centerY)
            })
            index += 1
        }
    }

}
